<h4>Edit User: <?php echo $this->user['pib'] ?></h4>

<div class="row">
    <div class="col-md-3 col-md-offset-3">
        <?php if ( count($this->errors) > 0 ): ?>
            <div class="alert alert-danger" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
                <ul>
                <?php foreach ($this->errors as $key => $field): ?>
                    <?php foreach ($field as $error): ?>
                        <li>Field <?php echo $key; ?>: <?php echo $error; ?></li>
                    <?php endforeach; ?>
                <?php endforeach; ?>
                </ul>
            </div>
        <?php endif; ?>
        <form action="" method="post">
            <div class="form-group">
                <label for="gid">Group Name</label>
                <select id="gid" name="gid" class="form-control">
                    <?php foreach ($this->groups as $group): ?>
                        <?php if ( $this->edit ): ?>
                            <option <?php if ( $group['id'] === $this->edit['gid'] ): ?>selected="selected"<?php endif; ?> value="<?php echo $group['id']; ?>"><?php echo $group['name']; ?></option>
                        <?php else: ?>
                            <option <?php if ( $group['id'] === $this->user['gid'] ): ?>selected="selected"<?php endif; ?> value="<?php echo $group['id']; ?>"><?php echo $group['name']; ?></option>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="form-group">
                <label for="pib">PIB</label>
                <input type="text" class="form-control" id="pib" placeholder="PIB" name="pib" value="<?php echo ($this->edit ? $this->edit['pib'] : $this->user['pib']); ?>" />
            </div>
            <div class="form-group">
                <label for="email">Email</label>
                <input type="text" class="form-control" id="email" placeholder="Email" name="email" value="<?php echo ($this->edit ? $this->edit['email'] : $this->user['email']); ?>" />
            </div>
            <div class="form-group">
                <label for="phone">Phone</label>
                <input type="text" class="form-control" id="phone" placeholder="Phone" name="phone" value="<?php echo ($this->edit ? $this->edit['phone'] : $this->user['phone']); ?>" />
            </div>
            <div class="form-group">
                <label for="pass">Password</label>
                <input type="password" class="form-control" id="pass" placeholder="Password" name="pass" value="<?php echo ($this->edit ? $this->edit['pass'] : $this->user['pass']); ?>" />
            </div>
            <div class="form-group">
                <label for="verify">Confirm</label>
                <input type="password" class="form-control" id="verify" placeholder="Confirm Password" name="verify" value="<?php echo ($this->edit ? $this->edit['verify'] : $this->user['pass']); ?>" />
            </div>
            <button type="submit" class="btn btn-default">Save User</button>
            <a class="btn btn-default" href="<?php echo url('user/users'); ?>">Cancel</a>
        </form>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function(){
        $("#phone").mask("(999) 999-9999");
    });
</script>